﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;

namespace SD.Database.Classes
{
    public class StaticMethods
    {
        public static string GetMd5Sum(string str)
        {
            // First we need to convert the string into bytes, which
            // means using a text encoder.
            Encoder enc = System.Text.Encoding.Unicode.GetEncoder();

            // Create a buffer large enough to hold the string
            byte[] unicodeText = new byte[str.Length * 2];
            enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);

            // Now that we have a byte array we can ask the CSP to hash it
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] result = md5.ComputeHash(unicodeText);

            // Build the final string by converting each byte
            // into hex and appending it to a StringBuilder
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < result.Length; i++)
            {
                sb.Append(result[i].ToString("X2"));
            }

            // And return it
            return sb.ToString();
        }

        public static string ConnectionString()
        {
            return @"Data Source=.\SQLExpress;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=smalldeimos_smallDeimos";
            //return @"Data Source=sql2005.hostedwindows.pl;Initial Catalog=smalldeimos;User Id=sd_user;Password=smallDeimos;";
            //return "Context Connection=true";
             //return @"Data Source=PLKRK-L-L3WWXHF\SQL2005;Initial Catalog=smallDeimos;Integrated Security=True";
        }

        public static bool ValidateMsg(string msg)
        {
            if (msg.Contains("javascript") == true)
                return false;
            if (msg.Contains("sysobjects") == true || msg.Contains("syscolumns") == true)
                return false;
            if (msg.Replace(" ", "").ToLower().Contains("droptable") == true)
                return false;
            if (msg.Replace(" ", "").ToLower().Contains("altertable") == true)
                return false;
            if (msg.Replace(" ", "").ToLower().Contains("deletefrom") == true)
                return false;
            if (msg.Replace(" ", "").ToLower().Contains("insertinto") == true)
                return false;

            return true;
        }
    }
}
